const Sequelize = require('sequelize');
const bcrypt = require('bcrypt');
const sequelize = require('../utils/mysql');
const validator = require('validator');

const User = sequelize.define('user', {
    username:{
        type: Sequelize.STRING,
        primaryKey: true,
    },
    password: {
        type: Sequelize.STRING,
    },
    preference:{
        type: Sequelize.STRING,
    }
});

User.prototype.checkPassword = async function(pw){
    const result = await bcrypt.compare(pw,this.password);
    return result;
};

User.validateName = function (name) {
    return validator.isEmail(name);
};

// User.sync({force:true});

module.exports = User;